using System;
using System.ComponentModel;
using System.Collections.Generic;

namespace shfa.snomtastic.data.business
{
	[DataObject(true)]
    public partial class SettingController
    {
	
		public SqlDataProvider DataProvider { get; set; }

        public SettingController()
        {
            DataProvider = new SqlDataProvider();
        }
	
		[DataObjectMethod(DataObjectMethodType.Insert, true)]
        public Guid InsertSetting(SettingInfo oi)
		{
            return DataProvider.InsertSetting(oi.CategoryId, oi.SubcategoryId, oi.Name, oi.SettingIndex, oi.Encrypted);
		}

		[DataObjectMethod(DataObjectMethodType.Update, true)]
        public int UpdateSetting(SettingInfo oi) 
		{
			return DataProvider.UpdateSetting(oi.SettingId, oi.CategoryId, oi.SubcategoryId, oi.Name, oi.SettingIndex, oi.Encrypted);
		}
		
		[DataObjectMethod(DataObjectMethodType.Delete, true)]
        public int DeleteSetting(Guid settingId)
		{
			return DataProvider.DeleteSetting(settingId);
        }

		[DataObjectMethod(DataObjectMethodType.Select, true)]
        public SettingInfo SelectSetting(Guid settingId)
        {    
			return ObjectFromDataRow(DataProvider.SelectSetting(settingId));
        }
		
		[DataObjectMethod(DataObjectMethodType.Select, true)]
        public List<SettingInfo> SelectSettings()
		{
            return ListFromDataTable(DataProvider.SelectSettings());
        }
		
		[DataObjectMethod(DataObjectMethodType.Select, true)]
        public List<SettingInfo> SelectSettings(string sortExpression)
        {
            List<SettingInfo> retList = SelectSettings();
            if (sortExpression.Length > 0)
            {
                retList.Sort(new SettingComparer(sortExpression));
            }
            return retList;
        }

        [DataObjectMethod(DataObjectMethodType.Select, true)]
		public List<SettingInfo> SelectSettingsByCategory(Guid categoryId)
		{
			return ListFromDataTable(DataProvider.SelectSettingsByCategory(categoryId));
		}
		
        public List<SettingInfo> SelectSettingsByCategory(Guid categoryId,string sortExpression)
		{
			List<SettingInfo> retList = SelectSettingsByCategory(categoryId);
            if (sortExpression.Length > 0)
            {
                retList.Sort(new SettingComparer(sortExpression));
            }
            return retList;
		}

        [DataObjectMethod(DataObjectMethodType.Select, true)]
		public List<SettingInfo> SelectSettingsBySubcategory(Guid subcategoryId)
		{
			return ListFromDataTable(DataProvider.SelectSettingsBySubcategory(subcategoryId));
		}
		
        public List<SettingInfo> SelectSettingsBySubcategory(Guid subcategoryId,string sortExpression)
		{
			List<SettingInfo> retList = SelectSettingsBySubcategory(subcategoryId);
            if (sortExpression.Length > 0)
            {
                retList.Sort(new SettingComparer(sortExpression));
            }
            return retList;
		}

	}

}
		